import { HomePageMediaCoverageItem } from './home';
import { $http } from './index';

export interface strategySpecsItem {
    mediaType: number; //  1-智能屏、2-LCD、3-电梯海报
    duration?: number; // 媒体类型是智慧屏或者LCD时才有值
    frequency?: number; // 媒体类型是智慧屏或者LCD时才有值
    framePublishMethod?: number; // 1:一梯一框、2:一梯两框、3:包梯 媒体类型时框时此字段才有值
    startDate: string;
    endDate: string;
}

export interface cphItem {
    premisesNum: number;
    screenPointNum: number;
    lcdPointNum: number;
    framePointNum: number;
    value: string;
}

export interface StrategyStatisticsListRes {
    projectId: string;
    optimal: boolean; // 是否最优 true-最优
    price: string; // 预估价格/元
    mediaTypes: number[];
    cph: cphItem;
    mediaResource: {
        resourceSummary: HomePageMediaCoverageItem; // 资源总览
        mediaResourceSummaryList: HomePageMediaCoverageItem[]; // 媒体资源汇总
    };
    ownerMediaResourceSummaryList: {
        resourceOwner: number; // 资源方
        resourceSummaryList: HomePageMediaCoverageItem[];
        price: string;
    }; // 资源方媒体资源汇总
    deliveryModes: strategySpecsItem[]; // 投放策略规格
}

export interface ResourceDetailsReq {
    projectId: number;
    strategyId: number;
    resourceOwner: number; // 资源方 1-新潮 2-分众
    mediaType: number; // 媒体资源类型 1-智能屏、2-LCD、3-电梯海报
}

export interface ResourceDetailsRes {
    id?: string;
    projectId: number; // 方案id
    strategyId: number; // 策略id（竞价方案有用）
    cityCode?: string;
    cityName?: string;
    premisesId?: string; // 楼盘id
    premiseName?: string;
    resourceOwner?: number; // 资源方 1-新潮 2-分众
    mediaType?: number; // 媒体类型 1-智能屏、2-LCD、3-电梯海报
    pointNum?: number; // 点位数
    coveredHousehold?: number; // 覆盖家庭数
    coveredPeople?: number; // 覆盖人数
    coveredBuildingNum?: number; // 覆盖楼栋数
    coveredElevator?: number; // 覆盖电梯数
}

export interface StrategyStatisticsReq {
    projectId: string;
    cityCodes?: string[];
    areaCodes?: string[];
    addresses?: {
        longitude: number;
        latitude: number;
        radius: number;
    }[];
    mediaTypes?: number[];
    optimalMediaType?: number;
    premisesTypes?: string[];
    premisesPrices?: number[];
    premisesAges?: number[];
    inHouseRates?: number[];
    parkingNums?: number[];
    propertyFees?: number[];
    strategySpecs?: strategySpecsItem[];
    businessScenario?: number,
    pointSelectionMode?:number
}

export interface listResourceDetailsReq {
    projectId: string;
    strategyId?:string;
    resourceOwner:number;
    mediaType:number;
    pageNum:number;
    pageSize:number
}
export interface IResItem {
    cityName:string,
    premiseName:string,
    pointNum:number,
    coveredPeople:number,
    coveredHousehold:number
}
export interface listResourceDetailsRes {
    records:IResItem[]
}

export interface StrategyStatisticsRes {
    projectId: string;
    optimal: boolean;
    price: string;
    cph: cphItem;
    pointSelectionMode:number, // 1.全城 2.半城
    mediaTypes: number[];
    mediaResource: {
        resourceSummary: HomePageMediaCoverageItem;
        mediaResourceSummaryList: HomePageMediaCoverageItem[]; // 媒体资源汇总
        ownerMediaResourceSummaryList?: {
            resourceOwner: number; // 资源方
            resourceSummaryList: HomePageMediaCoverageItem[];
            price: string;
        }[]; // 资源方媒体资源汇总
    };
}
export interface DeliveryProcessRes {
    budget: number;
    cost: number;
    percent: string;
    beginDate: string;
    endDate: string;
    publishStatisticList: { [key: string]: number | string }[];
}

export interface calFzStrategyPriceReq {
    projectId: string;
    screenPrice?:number;
    lcdPrice?:number;
}
export interface calFzStrategyPriceRes {
   data:number
}

// const baseOrigin = 'http://10.200.90.67:9000';

// 获取策略调整列表
export function getStrategyStatisticsList(params: StrategyStatisticsReq): Promise<StrategyStatisticsRes[]> {
    return $http.post('/project/listStrategyStatistics', params);
}

// 获取方案媒体资源明细
export function getResourceDetails(params: ResourceDetailsReq): Promise<StrategyStatisticsListRes> {
    return $http.post('/project/listResourceDetails', params);
}

// 投放页面获取投放策略信息
export function getStrategyStatistics(params: StrategyStatisticsReq): Promise<StrategyStatisticsRes> {
    return $http.post('/project/getStrategyStatistics', params);
}

// 保存投放策略
export function saveStrategySpecs(params: StrategyStatisticsReq): Promise<string> {
    return $http.post('/project/saveStrategySpecs', params);
}

// 获取方案媒体策略
export function getMediaStrategy(projectId: string): Promise<StrategyStatisticsRes> {
    return $http.get('/project/getMediaStrategy?projectId=' + projectId);
}
export function dailyDeliveryProcess(projectId: string): Promise<DeliveryProcessRes> {
    return $http.post('/project/dailyDeliveryProcess?projectId=' + projectId);
}
export function listResourceDetails(params: listResourceDetailsReq): Promise<listResourceDetailsRes> {
    return $http.post('/project/listResourceDetails',params);
}
export function calFzStrategyPrice(params: calFzStrategyPriceReq): Promise<calFzStrategyPriceRes>{
    return $http.post('/project/calFzStrategyPrice',params);
}
